#include <unistd.h>
#include <string.h>
#include"api/api.h"
int mycb(void * obj, asrMsg* pMsg, int uselss)
{
	printf("\n\nmycb Pointer %p\n\n\n",obj);
	int*  pInt = (int*)(obj);
	*pInt = pMsg->_iCommand; 
	
	printf("command is %d\n", pMsg->_iCommand);
	if(pMsg->_pAsrRes)
	{
		printf("Index : %d\n",pMsg->_pAsrRes->_iIndex);
		if(pMsg->_pAsrRes->_pRes)
			printf("asr res is %s\n",pMsg->_pAsrRes->_pRes);
		printf("BeginTime is %d ms\n",pMsg->_pAsrRes->_iBeginTime);
		printf("file = %s\n",pMsg->_pAsrRes->_file);
	}
}
int main()
{
	//example
	int i = 0;
	printf("Main Pointer %p\n",&i);
    const char* uuid="test123";
	vadOptions options;
	memset(&options,0,sizeof(vadOptions));
	options._iVadRenderId = RECO_WEBRTC;
	options._iVadRenderGiven =1;
	
    void* proxy = pCreateRecoProxy(uuid,strlen(uuid),&i,&options,NULL,mycb);

	//pFeedDataToRecoProxy(proxy,NULL,0);
	//pFeedDataToRecoProxy(proxy,NULL,0);
	//FILE* pcmfd = fopen("./29.pcm", "rb");
	FILE* pcmfd = fopen("./iat_pcm_8k_2.pcm", "rb");
    fseek(pcmfd, 0, SEEK_END);
    long wav_length = ftell(pcmfd);
    printf("wav file length = %ld Byte\n", wav_length);
    fseek(pcmfd, 0, SEEK_SET);
	char* buf = (char*)malloc(320);
	int iLen = fread(buf, 1, 320, pcmfd);
	//if(iLen > 0)
		//printf("buf is %s, iLen=%d\n",buf,iLen);
	while (iLen >0)
	{
		pFeedDataToRecoProxy(proxy,buf,iLen);
		iLen = fread(buf, 1, 320, pcmfd);
	}
	fclose(pcmfd);
	free(buf);
	//wait for res, after get res then close
	//sleep(12);
	pCloseRecoProxy(proxy);
	//after get final res, then we close it
	return 0;
}
